<!--
* @author: lzm
* @date: 2023年11月27日10:52:10
* @description：人员管理新增/编辑弹窗
* @update: 2023年11月27日10:52:16
-->
<template>
  <div>
    <el-dialog
      :title='title'
      :visible='showDialog'
      width='1016px'
      center
      top='5vh'
      custom-class='my-dialog hardConfig'
      :close-on-click-modal='false'
      :close-on-press-escape='false'
      :append-to-body='true'
      @close='close'>
      <div class='content'>
        <div class='outbound'>
          <div class='add-tip flex flex-a-center' v-if='outBoundList.length>0'>
            <div class='left'>
              <img src='@/assets/shelf_manage_img/outbound-icon.png' />
              领用出库
            </div>
            <div class='right' v-if='model !== 1 && isType === 1'>
              <el-button
                class='chamfer-corners-10'
                type='primary'
                @click='bindTask'>
                一键绑定任务
              </el-button>
            </div>
          </div>
          <div class='items'>
            <div
              class='item'
              v-for='(item, index) in outBoundList'
              :key='index'>
              <div class='shelfLocation' v-if='model !== 3 || isType !== item.type'>
                <!--                如果和任务没关则显示实时出入库-->
                {{ item.shelvesName }}{{ item.shelvesCode }}-{{ item.layerSort }}-{{ item.sort || item.positionName}}
              </div>
              <div class='shelfLocation-btn' v-else>
                <el-button
                  class='chamfer-corners-5'
                  size='mini'
                  type='primary'
                  @click='useBtn(item)'>
                  领用详情
                </el-button>
              </div>
              <div class='item-title'>
                <div class='img-box'>
                  <img v-if='item.goodsImage' :src='item.goodsImage' />
                  <img
                    v-else
                    src='@/assets/shelf_manage_img/shelf-item.png'
                  />
                </div>
                <div class='detail-box'>
                  <div class='name'>{{ item.goodsName }}</div>
                  <div class='model'>{{ item.goodsModel }}</div>
                </div>
              </div>
              <div class='item-content'>
                <div class='item-content-p'>
                  <p>领用时间：</p>
                  <p>{{ item.receiveTime || nowTime }}</p>
                </div>
                <div class='item-content-p' v-if='model !== 1 && isType === item.type'>
                  <p>所属任务：</p>
                  <p class='ellipsis'>{{ item.taskName || '--' }}</p>
                </div>
                <div class='item-content-p' v-if='(model !== 1||item.isHand) && isType === item.type'>
                  <p>待领数量：</p>
                  <p>{{ item.planCount }}</p>
                </div>
                <div class='item-content-p'>
                  <p>实领数量：</p>
                  <p>{{ item.realCount || 0 }}</p>
                </div>
                <div class='item-content-p'
                     v-if='(model !== 1||item.isHand) && isType === item.type && item.planCount && item.planCount > 0'>
                  <p>领用状态：</p>
                  <!-- 出入库状态 1-正常 2-多拿 3-少拿"-->
                  <p v-if='!item.realCount'>未领用</p>
                  <p
                    v-else
                    :class="
                        item.planCount == item.realCount
                          ? 'normal'
                          : item.planCount < item.realCount
                          ? 'danger'
                          : 'warning'
                      "
                  >
                    {{
                      item.planCount == item.realCount
                        ? '正常'
                        : item.planCount < item.realCount
                          ? '多拿'
                          : '少拿'
                    }}
                  </p>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class='warehousing'>
          <div class='add-tip flex flex-a-center' v-if='wareHousingList.length>0'>
            <div class='left'>
              <img src='@/assets/shelf_manage_img/warehousing-icon.png' />
              归还入库
            </div>
            <div class='right' v-if='model !== 1 && isType === 2'>
              <el-button
                class='chamfer-corners-10'
                type='primary'
                @click='bindTask'>
                一键绑定任务
              </el-button>
            </div>
          </div>
          <div class='items'>
            <div
              class='item'
              v-for='(item, index) in wareHousingList'
              :key='index'>
              <div class='shelfLocation' v-if='model !== 3 || isType !== item.type'>
                {{ item.shelvesName }}{{ item.shelvesCode }}-{{ item.layerSort }}-{{ item.sort || item.positionName }}
              </div>
              <div class='shelfLocation-btn' v-else>
                <el-button
                  class='chamfer-corners-5'
                  size='mini'
                  type='primary'
                  @click='useBtn(item)'>
                  归还详情
                </el-button>
              </div>
              <div class='item-title'>
                <div class='img-box'>
                  <img v-if='item.goodsImage' :src='item.goodsImage' />
                  <img v-else src='@/assets/shelf_manage_img/shelf-item.png' />
                </div>
                <div class='detail-box'>
                  <div class='name'>{{ item.goodsName }}</div>
                  <div class='model'>{{ item.goodsModel }}</div>
                </div>
              </div>
              <div class='item-content'>
                <div class='item-content-p'>
                  <p>归还时间：</p>
                  <p>{{ item.receiveTime || nowTime }}</p>
                </div>
                <div class='item-content-p' v-if='(model !== 1||item.isHand) && isType === item.type'>
                  <p>所属任务：</p>
                  <p class='ellipsis'>{{ item.taskName }}</p>
                </div>
                <div class='item-content-p' v-if='(model !== 1||item.isHand) && isType === item.type'>
                  <p>待还数量：</p>
                  <p>{{ item.planCount }}</p>
                </div>
                <div class='item-content-p'>
                  <p>归还数量：</p>
                  <p>{{ item.realCount }}</p>
                </div>
                <div class='item-content-p'
                     v-if='(model !== 1||item.isHand) && isType === item.type && item.planCount && item.planCount > 0'>
                  <p>归还状态：</p>
                  <p v-if='!item.realCount'>未归还</p>
                  <p
                    v-else
                    :class="
                        item.planCount == item.realCount
                          ? 'normal'
                          : item.planCount < item.realCount
                          ? 'danger'
                          : 'warning'
                      "
                  >
                    {{
                      item.planCount == item.realCount
                        ? '正常'
                        : item.planCount < item.realCount
                          ? '多还'
                          : '少还'
                    }}
                  </p>
                  <!--                  <p :class="item.status == 1-->
                  <!--                        ? 'normal'-->
                  <!--                        : item.status == 2-->
                  <!--                        ? 'danger'-->
                  <!--                        : 'primary'-->
                  <!--                    "-->
                  <!--                  >-->
                  <!--                    {{-->
                  <!--                      item.status == 1-->
                  <!--                        ? '已归还'-->
                  <!--                        : item.status == 2-->
                  <!--                          ? '未归还'-->
                  <!--                          : '&#45;&#45;'-->
                  <!--                    }}-->
                  <!--                  </p>-->
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class='footer'>
        <el-button
          type='primary'
          :loading='loading'
          class='chamfer-corners-8'
          @click='configBtn'>
          确认
          <span v-if='second > 0'>{{ second }}s</span>
        </el-button>
      </div>
    </el-dialog>

    <el-dialog
      append-to-body
      :close-on-click-modal='false'
      :close-on-press-escape='false'
      title='填写操作人'
      :visible.sync='showOperatorDialog'
      width='600px'
      center
      custom-class='my-dialog'>
      <div class='form-top' style='height: 150px'>
        <el-form ref='addForm' :model='addForm' :rules='rules' label-width='100px'>
          <el-form-item label='操作人'>
            <el-input
              v-model='addForm.nickName'
              placeholder='请输入操作人名称'
            />
          </el-form-item>
        </el-form>
      </div>
      <div class='footer flex flex-center'>
        <el-button
          type='primary'
          class='chamfer-corners-8'
          @click='confirmBtn'>
          确认 {{ secondOperSure }}
        </el-button>
      </div>
    </el-dialog>
    <use-details ref='useDetails' :showUseDialog.sync='showUseDialog' :id='detailId' :inOutList='inOutList' />
  </div>
</template>
<script>
import { parseTime } from '@/utils'
import useDetails from './components/useDetails.vue'
import { lampPosition, lampGoods, closeLamp } from '@/api/smartShelf.js'
import { saveHand, saveUseOrGoods, inoutRecordSave } from '@/api/realTimeStorage'
import {mapGetters} from "vuex";

import { EventBus } from '@/utils/eventBus'

export default {
  components: { useDetails },
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    // 任务id
    taskId: {
      type: String,
      default: ''
    },
    // 任务详情id
    taskDetailId: {
      type: String,
      default: ''
    },
    taskName: {
      type: String,
      default: '默认任务'
    },
    nickName: {
      type: String,
      default: ''
    },
    title: {
      type: String,
      default: '实时出入库'
    },
    // webSocket返回数据
    inOutList: {
      type: Array,
      default() {
        return []
      }
    },
    // 列表数据/获取选中数据
    goodsList: {
      type: Array,
      default() {
        return []
      }
    },
    // 1-实时出入库(positionId) 2-货架选中物品领用(positionId)  3-物料列表(goodsId)/任务列表领用(id->goodsId)
    model: {
      type: Number,
      default: 1
    },
    // 出入库状态
    isType: {
      type: [Number, String],
      default: 0
    }
  },
  data() {
    return {
      showOperatorDialog: false,
      addForm: {
        // 操作人
        nickName: ''
      },
      rules: {
        nickName: [
          { required: true, message: '请输入操作人', trigger: 'blur' }
        ]
      },
      itemData: [],
      // 出库列表
      outBoundList: [],
      // 入库列表
      wareHousingList: [],
      // 出库列表
      outBoundBackList: [],
      // 入库列表
      wareHousingBackList: [],
      // 控制领用详情弹窗
      showUseDialog: false,
      // 领用详情id
      detailId: null,
      // 倒计时秒数
      // second: 60,
      // 倒计时定时器
      timer: null,
      secondOperSure: 60,
      // 倒计时定时器
      timerOperSure: null,
      // 按钮加载
      loading: false,
      //
      realWsData: [],
      // 存在任务列表但是没有任务的走实时出入库
      noTaskArr: [],
      // 当前时间
      nowTime: ''
    }
  },
  mounted() {
  },
  computed: {
    ...mapGetters(['userInfo', 'isLogin']),
  },
  watch: {
    // ws推送的数据    出入库类型 0-正常 1-出库 2-入库
    inOutList: {
      handler(val) {
        if (!val.length) {
          if (this.model === 1) {
            this.showOperatorDialog = false
            this.$emit('closeDialog')
            return
          }
          this.outBoundList.forEach(item => {
            item.realCount = 0
          })
          this.wareHousingList.forEach(item => {
            item.realCount = 0
          })
          if (this.isType === 1) {
            // 出库
            this.wareHousingList = this.wareHousingList.filter(item => item.realCount > 0)
            this.outBoundList = this.outBoundList.filter(item => item.taskName || (!item.taskName && item.realCount > 0))
          } else if (this.isType === 2) {
            this.outBoundList = this.outBoundList.filter(item => item.realCount > 0)
            this.wareHousingList = this.wareHousingList.filter(item => item.taskName || (!item.taskName && item.realCount > 0))
          }
          return
        }
        if (this.model === 1) {
          this.wareHousingList = this.wareHousingList.filter(item => item.realCount > 0)
          this.outBoundList = this.outBoundList.filter(item => item.realCount > 0)
        }
        // if (this.second <= 0) {
        //   this.second = 60
        // }

        this.loading = false
        this.realWsData = []
        // if (this.timer) {
        //   clearInterval(this.timer)
        //   this.timer = null
        // }
        let action = false
        let idFiled = this.model === 3 ? 'goodsId' : 'positionId'
        // 出库列表
        if (this.outBoundList.length > 0) {
          let idMap = {}
          let outList = val.filter((item) => item.type === 1)
          outList.forEach(item => {
            const id = item[idFiled]
            const num = item.realCount
            if (idMap[id]) {
              idMap[id] += num
            } else {
              idMap[id] = num
            }
          })
          // 更新出库数量
          this.outBoundList.forEach(item => {
            const id = item[idFiled]
            if (idMap[id] !== item.realCount) {
              console.log('存在不一致的数据')
              action = true
            }
            item.realCount = idMap[id] || 0
          })
          // 获取ws中新增的数据
          let addList = val.filter(item => {
            return !this.outBoundList.some(item2 => item2[idFiled] === item[idFiled])
          })
          // ws新增并且type为1的数据
          let addOutList = addList.filter(item => item.type === 1)
          let newAddList = JSON.parse(JSON.stringify(addOutList))
          this.outBoundList = [...this.outBoundList, ...newAddList]
        } else {
          let arr = val.filter((item) => item.type === 1)
          let outList = JSON.parse(JSON.stringify(arr))

          this.outBoundList = outList
        }
        if (this.wareHousingList.length > 0) {
          let idMap = {}
          let inList = val.filter((item) => item.type === 2)
          inList.forEach(item => {
            const id = item[idFiled]
            const num = item.realCount
            if (idMap[id]) {
              idMap[id] += num
            } else {
              idMap[id] = num
            }
          })
          // 更新入库数量
          this.wareHousingList.forEach(item => {
            const id = item[idFiled]
            if (idMap[id] !== item.realCount) {
              console.log('存在不一致的数据')
              action = true
            }
            item.realCount = idMap[id] || 0
          })
          // 获取ws中新增的数据
          let addList = val.filter(item => {
            return !this.wareHousingList.some(item2 => item2[idFiled] === item[idFiled])
          })
          // ws新增并且type为2的数据
          let addInList = addList.filter(item => item.type === 2)
          let newAddList = JSON.parse(JSON.stringify(addInList))
          this.wareHousingList = [...this.wareHousingList, ...newAddList]
        } else {
          let arr = val.filter((item) => item.type === 2)
          let inList = JSON.parse(JSON.stringify(arr))

          this.wareHousingList = inList
        }
        // 存储真正的ws推送的数据
        if (this.model === 1) {
          this.realWsData = val
        } else {
          // 取出ws中新增的数据
          let addList = val.filter(item => {
            return !this.goodsList.some(item2 => item2[idFiled] === item[idFiled])
          })
          this.realWsData = addList
        }
        if (this.isType === 1) {
          // 出库
          this.wareHousingList = this.wareHousingList.filter(item => item.realCount > 0)
          this.outBoundList = this.outBoundList.filter(item => item.taskName || (!item.taskName && item.realCount > 0))
        } else if (this.isType === 2) {
          this.outBoundList = this.outBoundList.filter(item => item.realCount > 0)
          this.wareHousingList = this.wareHousingList.filter(item => item.taskName || (!item.taskName && item.realCount > 0))
        }
        // console.log(action)
        this.wareHousingBackList = []
        this.wareHousingBackList.push(...this.wareHousingList)
        this.outBoundBackList = []
        this.outBoundBackList.push(...this.outBoundList)
        // 重置倒计时
        if (action) {
          // 有发生变化，重置到期时间
          this.countDown(60)
        }

      },
      deep: true
    },
    showDialog(val) {
      if (!val) {
        this.second = 60
        this.loading = false
        this.realWsData = []
        this.outBoundList = []
        this.wareHousingList = []
        this.$store.commit('settings/CHANGE_SETTING', {
          key: 'isRealTimeOpen',
          value: false
        })
        if (this.timer) {
          clearInterval(this.timer)
          this.timer = null
        }
        // 出库列表
        // outBoundList: [],
        //   // 入库列表
        //   wareHousingList: [],
        let data = this.closeLampData()
        closeLamp(data).then(res => {
        })
      } else {
        // 出入库类型 0-正常 1-出库 2-入库
        // 数组深拷贝
        let newList = JSON.parse(JSON.stringify(this.goodsList))
        this.outBoundList = newList.filter((item) => item.type === 1)
        this.wareHousingList = newList.filter((item) => item.type === 2)
        this.nowTime = parseTime(new Date().getTime(), '{y}-{m}-{d} {h}:{i}:{s}')
        this.countDown(60)

        console.log(newList)
        let arr = []
        if (this.model === 2) {
          newList.map(item => {
            let info = {
              id: item.positionId,
              number: item.planCount
            }
            arr.push(info)
          })
          if (arr.length) {
            let info = {
              status: true,
              type: this.isType,
              list: arr
            }
            lampPosition(info).then(res => {
              console.log(res)
            })
          }

        }
        if (this.model === 3) {
          newList.map(item => {
            // arr.push(item.id)
            let info = {
              id: item.goodsId,
              number: item.planCount
            }
            arr.push(info)
          })
          if (arr.length) {
            let info = {
              status: true,
              type: this.isType,
              list: arr
            }
            lampGoods(info).then(res => {
              console.log(res)
            })
          }
        }

        this.wareHousingBackList = []
        this.wareHousingBackList.push(...this.wareHousingList)
        this.outBoundBackList = []
        this.outBoundBackList.push(...this.outBoundList)

      }
    }
  },
  methods: {
    closeLampData(){
      let goodsIds = []
      let positionIds = []
      if (this.outBoundBackList.length > 0) {
        if (this.model === 3) {
          let ids = this.outBoundBackList.map(item=>{return item.goodsId})
          if (ids.length > 0) {
            goodsIds.push(...ids)
          }
        } else {
          let ids = this.outBoundBackList.map(item=>{return item.positionId})
          if (ids.length > 0) {
            positionIds.push(...ids)
          }
        }
      }
      if (this.wareHousingBackList.length > 0) {
        if (this.model === 3) {
          let ids = this.wareHousingBackList.map(item=>{return item.goodsId})
          if (ids.length > 0) {
            goodsIds.push(...ids)
          }
        } else {
          let ids = this.wareHousingBackList.map(item=>{return item.positionId})
          if (ids.length > 0) {
            positionIds.push(...ids)
          }
        }
      }
      console.log(this.outBoundList,'out')
      console.log(this.outBoundBackList,'outBack')
      console.log(this.wareHousingList,'ware')
      console.log(this.wareHousingBackList,'wareBack')
      let data = {
        goodsIds: null,
        positionIds: null
      }
      if (this.model === 3) {
        data.goodsIds = goodsIds
      } else {
        data.positionIds = positionIds
      }
      this.outBoundBackList = []
      this.wareHousingBackList = []
      return data
    },
    // 关闭弹窗事件
    close() {
      if (this.timer) {
        clearInterval(this.timer)
        this.timer = null
      }
      this.$store.commit('settings/CHANGE_SETTING', {
        key: 'isRealTimeOpen',
        value: false
      })
      let data = this.closeLampData()
      closeLamp(data).then(res => {
      })
      this.$emit('update:showDialog', false)

    },
    // 一键绑定任务
    bindTask() {
      if (this.isType === 1) {
        this.outBoundList.forEach((item) => {
          // 出入库类型 0-正常 1-出库 2-入库
          item.taskName = this.taskName
          item.planCount = item.planCount || 0
        })
      } else if (this.isType === 2) {
        this.wareHousingList.forEach((item) => {
          // 出入库类型 0-正常 1-出库 2-入库
          item.taskName = this.taskName
          item.planCount = item.planCount || 0
        })
      }
    },
    // 点击确认按钮
    configBtn() {
      this.noTaskArr = []
      this.loading = true
      this.wareHousingBackList = []
      this.wareHousingBackList.push(...this.wareHousingList)
      this.outBoundBackList = []
      this.outBoundBackList.push(...this.outBoundList)
      // 货架手动领用/归还
      if (this.model === 2) {
        if (this.isType === 1) {
          // 出库任务
          this.noTaskArr = this.outBoundList.filter(item => !item.taskName)
          this.outBoundList = this.outBoundList.filter(item => item.taskName)
        }
        if (this.isType === 2) {
          // 入库任务
          this.noTaskArr = this.wareHousingList.filter(item => !item.taskName)
          this.wareHousingList = this.wareHousingList.filter(item => item.taskName)
        }
        this.handMovement()
      }
      // 物料领用/任务领用
      if (this.model === 3) {
        // 通过物料、任务领用/归还
        if (this.isType === 1) {
          // 出库任务

          var arr = this.outBoundList.filter(item => !item.taskName)
          if (arr && arr.length > 0) {
            // 没有任务的
            var goodsIds = arr.map(item => item.goodsId)
            this.noTaskArr = this.inOutList.filter(inout => goodsIds.includes(inout.goodsId) && inout.type === this.isType)
            this.outBoundList = this.outBoundList.filter(item => item.taskName)
          }


        }
        if (this.isType === 2) {
          // 出库任务

          var arr = this.wareHousingList.filter(item => !item.taskName)
          if (arr && arr.length > 0) {
            // 没有任务的
            var goodsIds = arr.map(item => item.goodsId)
            this.noTaskArr = this.inOutList.filter(inout => goodsIds.includes(inout.goodsId) && inout.type === this.isType)
            this.wareHousingList = this.wareHousingList.filter(item => item.taskName)
          }
        }
        this.materialTask()
      }

      if (this.model === 1 && !this.isLogin){
        this.loading=false
        this.showOperatorDialog = true
        clearInterval(this.timer)
        this.countDownOper(60)
        return;
      }
      // 实时出入库单独接口
      this.inoutAutomatic()
      // if (this.model !== 3) {
      // this.$emit('operationCompleted')
      // }

    },
    // 货架手动领用/归还
    handMovement() {
      let that = this
      let arr = []
      let arrData = []
      if (this.model === 2 && this.isType === 1) {
        // 出库任务
        arrData = this.outBoundList
      } else if (this.model === 2 && this.isType === 2) {
        // 入库任务
        arrData = this.wareHousingList
      }
      if (this.isLogin && !this.nickName) {
        this.nickName = typeof this.userInfo ==='string'? JSON.parse(this.userInfo).nickName : this.userInfo.nickName
      }

      // 接口数据转换
      if (arrData.length) {
        arrData.map(item => {
          if (item.realCount > 0) {
            let info = {
              planCount: item.planCount,
              positionId: item.positionId,
              realCount: item.realCount,
              taskName: item.taskName,
              nickName: that.nickName,
              type: item.type
            }
            arr.push(info)
          }

        })
      }
      // console.log('手动领用/归还')
      // let isHandList = this.goodsList.filter((item) => item.isHand && item.realCount > 0)
      if (arr.length) {
        //  手动领用
        saveHand(arr)
          .then((res) => {
            this.loading = false
            this.$message.success('操作成功')
            this.$emit('operationCompleted')
          }).catch((err) => {
          this.loading = false
          this.$emit('operationCompleted')
        })
      } else {
        this.loading = false
        this.$emit('operationCompleted')
        // this.$message({
        //   message: '货位库存未发生改变',
        //   type:'error',
        //   showClose: true
        // })
      }
    },
    async materialTask() {
      let that = this
      if (this.isType === 1) {
        // 出库
        var list = this.outBoundList.filter(item => item.taskName && item.planCount === 0)
        this.goodsList.push(...list)
      } else if (this.isType === 2) {
        // 入库
        var list = this.wareHousingList.filter(item => item.taskName && item.planCount === 0)
        this.goodsList.push(...list)
      }

      this.goodsList.forEach(ele => {
        ele.detailList = this.inOutList.filter((item) => (item.goodsId === ele.goodsId && item.type === this.isType)).map(ele => {
          return Object.assign({}, { 'positionId': ele.positionId, 'realCount': ele.realCount })
        })
      })
      if (this.isLogin && !this.nickName) {
        this.nickName = typeof this.userInfo ==='string'? JSON.parse(this.userInfo).nickName : this.userInfo.nickName
      }
      let newList = this.goodsList.map(item => {
        item.realCount = item.detailList.reduce((accumulator, currentValue) => {
          return accumulator + currentValue.realCount
        }, 0)
        return Object.assign({}, {
          'goodsId': item.goodsId,
          'id': this.taskId ? item.id : '',
          'planCount': item.planCount,
          'realCount': item.realCount,
          'detailList': item.detailList
        })
      })
      let arr = newList.filter(item => item.realCount > 0)
      if (arr.length) {
        let obj = {
          id: this.taskId,
          type: this.isType,
          nickName: that.nickName ? that.nickName : '默认用户',
          name: this.taskName,
          goodsList: newList
        }
        await saveUseOrGoods(obj).then((res) => {
          this.loading = false
          this.$message.success('操作成功')
          this.$emit('operationCompleted')
        }).catch((err) => {
          this.loading = false
          this.$emit('operationCompleted')
        })
      } else {
        this.$emit('operationCompleted')
      }

    },
    confirmBtn() {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          this.showOperatorDialog = false
          this.loading=true
          this.inoutAutomatic()
        }
      })
    },
    inoutAutomatic() {
      // console.log('出入库数据')
      let arr = []
      if (this.model !== 1 && this.isType === 1) {
        // 出库任务
        arr = arr.concat(this.wareHousingList)
      } else if (this.model !== 1 && this.isType === 2) {
        // 入库任务
        arr = arr.concat(this.outBoundList)
      } else {
        // 没有任务
        arr = [...this.wareHousingList, ...this.outBoundList]
      }
      if (this.noTaskArr && this.noTaskArr.length > 0) {
        // arr.push(...this.noTaskArr)
        arr = arr.concat(this.noTaskArr)
      }
      if (arr.length > 0) {
        let nickName = this.model===1?this.addForm.nickName:this.nickName
        if (this.isLogin && !this.nickName) {
          nickName = typeof this.userInfo ==='string'? JSON.parse(this.userInfo).nickName : this.userInfo.nickName
        }
        arr.forEach(item => {
          item.nickName = nickName ? nickName : '默认用户'
        })
        // let outList = this.outBoundList.filter((item) => !item.isHand)
        // let inList = this.wareHousingList.filter((item) => !item.isHand)
        // let outData =[...outList,...inList]
        inoutRecordSave(arr).then((res) => {
          EventBus.$emit('refreshHomeData');
          this.loading = false
          this.$message.success('实时出入库操作成功')
          this.$emit('operationCompleted')
        }).catch(() => {
          this.loading = false
          this.$emit('operationCompleted')
        })
      } else {
        this.$emit('operationCompleted')
      }
    },
    // 按钮倒计时
    countDown(time) {
      if (this.timer) {
        clearInterval(this.timer)
        this.timer = null
      }
      if (time) {
        this.second = time
      }
      this.timer = setInterval(() => {
        // console.log(this.second)
        if (this.showOperatorDialog) return
        // this.second = time
        // time--
        this.second--
        if (this.second <= 0) {
          clearInterval(this.timer)
          this.timer = null
          this.configBtn()
        }
      }, 1000)
    },
    // 按钮倒计时
    countDownOper(time) {
      if (this.timerOperSure) {
        clearInterval(this.timerOperSure)
        this.timerOperSure = null
      }
      if (time) {
        this.secondOperSure = time
      }
      this.timerOperSure = setInterval(() => {
        // console.log(this.second)
        if (!this.showOperatorDialog) {
          this.timerOperSure = null
          this.secondOperSure = 60
        }
        // this.second = time
        // time--
        this.secondOperSure--
        if (this.secondOperSure <= 0) {
          clearInterval(this.timerOperSure)
          this.timerOperSure = null
          console.log('倒计时结束', this.timerOperSure)
          this.confirmBtn()
        }
      }, 1000)
    },
    // 领用详情弹窗
    useBtn(item) {
      this.showUseDialog = true
      // this.detailId = item.id || item.goodsId
      let arr = []
      if (this.model === 3) {
        // 物料/任务打开出入库弹框
        arr = this.inOutList.filter(inout => inout.goodsId === item.goodsId && inout.type === this.isType)
      }
      this.$refs.useDetails.initData(arr, this.isType)
    }
  },
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer)
      this.timer = null
    }
  }
}
</script>
<style scoped lang='scss'>
@import '~@/styles/_handle.scss';

::v-deep .el-dialog__body {
  padding: 25px 10px 30px 25px !important;
}

.hardConfig {
  margin-top: 5vh !important;

  .content {
    width: 100%;
    margin-bottom: 20px;
    height: 1000px;
    overflow-y: auto;

    .outbound,
    .warehousing {
      margin-bottom: 24px;

      .shelfLocation {
        text-align: right;
        font-weight: 500;
        font-size: 14px;
        color: #ffffff;
        margin-bottom: 8px;
      }

      .shelfLocation-btn {
        text-align: right;
        margin-bottom: 4px;

        .chamfer-corners-5 {
          font-size: 16px;
        }
      }

      .add-tip {
        height: 50px;
        line-height: 50px;
        width: 100%;
        font-weight: 500;
        font-size: 24px;
        color: #ffffff;
        @include background('dialog_div_tip_color');
        @include background-size('dialog_div_tip_size');
        -webkit-clip-path: polygon(
            10px 0,
            100% 0,
            100% 100%,
            10px 100%,
            0 calc(100% - 10px),
            0 10px
        );
        clip-path: polygon(
            10px 0,
            100% 0,
            100% 100%,
            10px 100%,
            0 calc(100% - 10px),
            0 10px
        );
        justify-content: space-between;
        align-items: center;

        .left {
          display: flex;
          align-items: center;

          img {
            width: 24px;
            margin: 0 10px 0 20px;
          }
        }

        .right {
          display: flex;
          align-items: center;
          margin-right: 12px;

          .chamfer-corners-10 {
            font-size: 16px;
          }
        }
      }

      .items {
        display: flex;
        flex-wrap: wrap;

        .item {
          width: 310px;
          padding: 16px;
          margin-right: 16px;
          margin-top: 16px;
          @include background('real_time_item_bg_color');

          &:nth-child(3n) {
            margin-right: 0;
          }

          -webkit-clip-path: polygon(
              10px 0,
              calc(100% - 10px) 0,
              100% 10px,
              100% calc(100% - 10px),
              calc(100% - 10px) 100%,
              10px 100%,
              0 calc(100% - 10px),
              0 10px
          );
          clip-path: polygon(
              10px 0,
              calc(100% - 10px) 0,
              100% 10px,
              100% calc(100% - 10px),
              calc(100% - 10px) 100%,
              10px 100%,
              0 calc(100% - 10px),
              0 10px
          );

          &-title {
            display: flex;
            align-items: center;

            .img-box {
              display: flex;
              align-items: center;
              justify-content: center;
              width: 56px;
              height: 56px;
              border: 1px solid;
              @include border_color('real_time_item_img_border_color');

              img {
                width: 48px;
                height: 48px;
              }
            }

            .detail-box {
              display: flex;
              flex-direction: column;
              justify-content: space-between;
              height: 48px;
              margin-left: 12px;
              color: #fff;

              .name {
                font-size: 18px;
              }

              .model {
                font-size: 16px;
              }
            }
          }

          &-content {
            font-size: 18px;
            color: #ffffff;
            display: flex;
            flex-direction: column;
            padding-top: 10px;

            &-p {
              display: flex;
              justify-content: space-between;
              margin-top: 10px;

              .ellipsis {
                width: 180px;
                text-align: right;
                white-space: nowrap; /* 文本不换行 */
                overflow: hidden; /* 溢出内容隐藏 */
                text-overflow: ellipsis; /* 显示省略号 */
              }

              p {
                margin: 0;
              }

              .normal {
                color: #02bc63;
              }

              .danger {
                color: #ff1f06;
              }

              .warning {
                color: #e2831e;
              }

              .primary {
                color: #fff;
              }
            }
          }
        }
      }
    }

    .warehousing {
      margin-bottom: 0;
      padding-bottom: 20px;
    }
  }

  .footer {
    text-align: center;

    .el-button {
      font-size: 18px;
    }
  }
}
</style>
